﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.Paint.DisplayCoverage.CUiPaintDisplayCoverageWindow
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.Paint.DeleteCoverage;
using DnProcessSimulateCommands.Paint.PaintDuringSimulation;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Threading;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui.WPF;
using UiInternalControls.WPF;


namespace DnProcessSimulateCommands.Paint.DisplayCoverage;

public class CUiPaintDisplayCoverageWindow : TxWindow, IComponentConnector
{
  private CApPaintDisplayCoverageViewModel m_apVM;
  private TxColorPalette m_colorPaletteWindow;
  private int m_editedColorIndex;
  internal System.Windows.Controls.CheckBox btnHSRFilter;
  internal System.Windows.Controls.CheckBox btnShowMeshes;
  internal System.Windows.Controls.CheckBox btnDisplayedCoverageMode;
  internal System.Windows.Controls.CheckBox btnDisplayedBrush;
  internal System.Windows.Controls.CheckBox btnDisplayedThicknessValue;
  internal Grid gColorScaleName;
  internal System.Windows.Controls.ComboBox cbScaleName;
  internal Grid gScale;
  internal StackPanel gScale_9;
  internal TxColorPickButton btnColorPicker_9;
  internal System.Windows.Controls.Label lblColorRange_9;
  internal StackPanel gScale_8;
  internal TxColorPickButton btnColorPicker_8;
  internal System.Windows.Controls.Label lblColorRange_8;
  internal StackPanel gScale_7;
  internal TxColorPickButton btnColorPicker_7;
  internal System.Windows.Controls.Label lblColorRange_7;
  internal StackPanel gScale_6;
  internal TxColorPickButton btnColorPicker_6;
  internal System.Windows.Controls.Label lblColorRange_6;
  internal StackPanel gScale_5;
  internal TxColorPickButton btnColorPicker_5;
  internal System.Windows.Controls.Label lblColorRange_5;
  internal StackPanel gScale_4;
  internal TxColorPickButton btnColorPicker_4;
  internal System.Windows.Controls.Label lblColorRange_4;
  internal StackPanel gScale_3;
  internal TxColorPickButton btnColorPicker_3;
  internal System.Windows.Controls.Label lblColorRange_3;
  internal StackPanel gScale_2;
  internal TxColorPickButton btnColorPicker_2;
  internal System.Windows.Controls.Label lblColorRange_2;
  internal StackPanel gScale_1;
  internal TxColorPickButton btnColorPicker_1;
  internal System.Windows.Controls.Label lblColorRange_1;
  internal System.Windows.Controls.Button btnReloadFiles;
  internal System.Windows.Controls.Button btnRemoveCoverage;
  internal System.Windows.Controls.Button btnClose;
  private bool _contentLoaded;

  public CUiPaintDisplayCoverageWindow()
  {
    this.InitializeComponent();
    this.m_apVM = new CApPaintDisplayCoverageViewModel();
    ((FrameworkElement) this).DataContext = (object) this.m_apVM;
    this.m_colorPaletteWindow = new TxColorPalette();
    this.InitializeDialog();
  }

  private void InitializeDialog()
  {
    CApPaintDisplayCoverageManager.Instance.IntializeViewModel(this.m_apVM);
    this.m_apVM.RegisterSimulationEvents();
    if (!CApPaintDuringSimulationManager.Instance.UsePaintThickness)
    {
      this.gColorScaleName.Visibility = Visibility.Collapsed;
      this.gColorScaleName.Height = 0.0;
      this.btnReloadFiles.Visibility = Visibility.Collapsed;
      this.btnReloadFiles.Height = 0.0;
      this.btnDisplayedThicknessValue.Visibility = Visibility.Collapsed;
      this.btnDisplayedThicknessValue.Height = 0.0;
    }
    else
      this.UpdateThicknessScaleInDialog();
  }

  public void UpdateThicknessScaleInDialog()
  {
    List<float> scaleValueList = this.m_apVM.ScaleValueList;
    string thicknessScaleName = this.m_apVM.SelectedThicknessScaleName;
    int num1 = scaleValueList.Count<float>();
    if (CApPaintDuringSimulationManager.Instance.UsePaintThickness)
    {
      string str1 = "≤  ";
      string str2 = ">  ";
      if (num1 > 8)
        num1 = 8;
      switch (num1)
      {
        case 1:
          System.Windows.Controls.Label lblColorRange2_1 = this.lblColorRange_2;
          string str3 = str2;
          float num2 = scaleValueList[0];
          string str4 = num2.ToString();
          string str5 = str3 + str4;
          lblColorRange2_1.Content = (object) str5;
          System.Windows.Controls.Label lblColorRange1_1 = this.lblColorRange_1;
          string str6 = str1;
          num2 = scaleValueList[0];
          string str7 = num2.ToString();
          string str8 = str6 + str7;
          lblColorRange1_1.Content = (object) str8;
          break;
        case 2:
          System.Windows.Controls.Label lblColorRange3_1 = this.lblColorRange_3;
          string str9 = str2;
          float num3 = scaleValueList[1];
          string str10 = num3.ToString();
          string str11 = str9 + str10;
          lblColorRange3_1.Content = (object) str11;
          System.Windows.Controls.Label lblColorRange2_2 = this.lblColorRange_2;
          string str12 = str1;
          num3 = scaleValueList[1];
          string str13 = num3.ToString();
          string str14 = str12 + str13;
          lblColorRange2_2.Content = (object) str14;
          System.Windows.Controls.Label lblColorRange1_2 = this.lblColorRange_1;
          string str15 = str1;
          num3 = scaleValueList[0];
          string str16 = num3.ToString();
          string str17 = str15 + str16;
          lblColorRange1_2.Content = (object) str17;
          break;
        case 3:
          System.Windows.Controls.Label lblColorRange4_1 = this.lblColorRange_4;
          string str18 = str2;
          float num4 = scaleValueList[2];
          string str19 = num4.ToString();
          string str20 = str18 + str19;
          lblColorRange4_1.Content = (object) str20;
          System.Windows.Controls.Label lblColorRange3_2 = this.lblColorRange_3;
          string str21 = str1;
          num4 = scaleValueList[2];
          string str22 = num4.ToString();
          string str23 = str21 + str22;
          lblColorRange3_2.Content = (object) str23;
          System.Windows.Controls.Label lblColorRange2_3 = this.lblColorRange_2;
          string str24 = str1;
          num4 = scaleValueList[1];
          string str25 = num4.ToString();
          string str26 = str24 + str25;
          lblColorRange2_3.Content = (object) str26;
          System.Windows.Controls.Label lblColorRange1_3 = this.lblColorRange_1;
          string str27 = str1;
          num4 = scaleValueList[0];
          string str28 = num4.ToString();
          string str29 = str27 + str28;
          lblColorRange1_3.Content = (object) str29;
          break;
        case 4:
          System.Windows.Controls.Label lblColorRange5_1 = this.lblColorRange_5;
          string str30 = str2;
          float num5 = scaleValueList[3];
          string str31 = num5.ToString();
          string str32 = str30 + str31;
          lblColorRange5_1.Content = (object) str32;
          System.Windows.Controls.Label lblColorRange4_2 = this.lblColorRange_4;
          string str33 = str1;
          num5 = scaleValueList[3];
          string str34 = num5.ToString();
          string str35 = str33 + str34;
          lblColorRange4_2.Content = (object) str35;
          System.Windows.Controls.Label lblColorRange3_3 = this.lblColorRange_3;
          string str36 = str1;
          num5 = scaleValueList[2];
          string str37 = num5.ToString();
          string str38 = str36 + str37;
          lblColorRange3_3.Content = (object) str38;
          System.Windows.Controls.Label lblColorRange2_4 = this.lblColorRange_2;
          string str39 = str1;
          num5 = scaleValueList[1];
          string str40 = num5.ToString();
          string str41 = str39 + str40;
          lblColorRange2_4.Content = (object) str41;
          System.Windows.Controls.Label lblColorRange1_4 = this.lblColorRange_1;
          string str42 = str1;
          num5 = scaleValueList[0];
          string str43 = num5.ToString();
          string str44 = str42 + str43;
          lblColorRange1_4.Content = (object) str44;
          break;
        case 5:
          System.Windows.Controls.Label lblColorRange6_1 = this.lblColorRange_6;
          string str45 = str2;
          float num6 = scaleValueList[4];
          string str46 = num6.ToString();
          string str47 = str45 + str46;
          lblColorRange6_1.Content = (object) str47;
          System.Windows.Controls.Label lblColorRange5_2 = this.lblColorRange_5;
          string str48 = str1;
          num6 = scaleValueList[4];
          string str49 = num6.ToString();
          string str50 = str48 + str49;
          lblColorRange5_2.Content = (object) str50;
          System.Windows.Controls.Label lblColorRange4_3 = this.lblColorRange_4;
          string str51 = str1;
          num6 = scaleValueList[3];
          string str52 = num6.ToString();
          string str53 = str51 + str52;
          lblColorRange4_3.Content = (object) str53;
          System.Windows.Controls.Label lblColorRange3_4 = this.lblColorRange_3;
          string str54 = str1;
          num6 = scaleValueList[2];
          string str55 = num6.ToString();
          string str56 = str54 + str55;
          lblColorRange3_4.Content = (object) str56;
          System.Windows.Controls.Label lblColorRange2_5 = this.lblColorRange_2;
          string str57 = str1;
          num6 = scaleValueList[1];
          string str58 = num6.ToString();
          string str59 = str57 + str58;
          lblColorRange2_5.Content = (object) str59;
          System.Windows.Controls.Label lblColorRange1_5 = this.lblColorRange_1;
          string str60 = str1;
          num6 = scaleValueList[0];
          string str61 = num6.ToString();
          string str62 = str60 + str61;
          lblColorRange1_5.Content = (object) str62;
          break;
        case 6:
          System.Windows.Controls.Label lblColorRange7_1 = this.lblColorRange_7;
          string str63 = str2;
          float num7 = scaleValueList[5];
          string str64 = num7.ToString();
          string str65 = str63 + str64;
          lblColorRange7_1.Content = (object) str65;
          System.Windows.Controls.Label lblColorRange6_2 = this.lblColorRange_6;
          string str66 = str1;
          num7 = scaleValueList[5];
          string str67 = num7.ToString();
          string str68 = str66 + str67;
          lblColorRange6_2.Content = (object) str68;
          System.Windows.Controls.Label lblColorRange5_3 = this.lblColorRange_5;
          string str69 = str1;
          num7 = scaleValueList[4];
          string str70 = num7.ToString();
          string str71 = str69 + str70;
          lblColorRange5_3.Content = (object) str71;
          System.Windows.Controls.Label lblColorRange4_4 = this.lblColorRange_4;
          string str72 = str1;
          num7 = scaleValueList[3];
          string str73 = num7.ToString();
          string str74 = str72 + str73;
          lblColorRange4_4.Content = (object) str74;
          System.Windows.Controls.Label lblColorRange3_5 = this.lblColorRange_3;
          string str75 = str1;
          num7 = scaleValueList[2];
          string str76 = num7.ToString();
          string str77 = str75 + str76;
          lblColorRange3_5.Content = (object) str77;
          System.Windows.Controls.Label lblColorRange2_6 = this.lblColorRange_2;
          string str78 = str1;
          num7 = scaleValueList[1];
          string str79 = num7.ToString();
          string str80 = str78 + str79;
          lblColorRange2_6.Content = (object) str80;
          System.Windows.Controls.Label lblColorRange1_6 = this.lblColorRange_1;
          string str81 = str1;
          num7 = scaleValueList[0];
          string str82 = num7.ToString();
          string str83 = str81 + str82;
          lblColorRange1_6.Content = (object) str83;
          break;
        case 7:
          System.Windows.Controls.Label lblColorRange8_1 = this.lblColorRange_8;
          string str84 = str2;
          float num8 = scaleValueList[6];
          string str85 = num8.ToString();
          string str86 = str84 + str85;
          lblColorRange8_1.Content = (object) str86;
          System.Windows.Controls.Label lblColorRange7_2 = this.lblColorRange_7;
          string str87 = str1;
          num8 = scaleValueList[6];
          string str88 = num8.ToString();
          string str89 = str87 + str88;
          lblColorRange7_2.Content = (object) str89;
          System.Windows.Controls.Label lblColorRange6_3 = this.lblColorRange_6;
          string str90 = str1;
          num8 = scaleValueList[5];
          string str91 = num8.ToString();
          string str92 = str90 + str91;
          lblColorRange6_3.Content = (object) str92;
          System.Windows.Controls.Label lblColorRange5_4 = this.lblColorRange_5;
          string str93 = str1;
          num8 = scaleValueList[4];
          string str94 = num8.ToString();
          string str95 = str93 + str94;
          lblColorRange5_4.Content = (object) str95;
          System.Windows.Controls.Label lblColorRange4_5 = this.lblColorRange_4;
          string str96 = str1;
          num8 = scaleValueList[3];
          string str97 = num8.ToString();
          string str98 = str96 + str97;
          lblColorRange4_5.Content = (object) str98;
          System.Windows.Controls.Label lblColorRange3_6 = this.lblColorRange_3;
          string str99 = str1;
          num8 = scaleValueList[2];
          string str100 = num8.ToString();
          string str101 = str99 + str100;
          lblColorRange3_6.Content = (object) str101;
          System.Windows.Controls.Label lblColorRange2_7 = this.lblColorRange_2;
          string str102 = str1;
          num8 = scaleValueList[1];
          string str103 = num8.ToString();
          string str104 = str102 + str103;
          lblColorRange2_7.Content = (object) str104;
          System.Windows.Controls.Label lblColorRange1_7 = this.lblColorRange_1;
          string str105 = str1;
          num8 = scaleValueList[0];
          string str106 = num8.ToString();
          string str107 = str105 + str106;
          lblColorRange1_7.Content = (object) str107;
          break;
        case 8:
          System.Windows.Controls.Label lblColorRange9 = this.lblColorRange_9;
          string str108 = str2;
          float num9 = scaleValueList[7];
          string str109 = num9.ToString();
          string str110 = str108 + str109;
          lblColorRange9.Content = (object) str110;
          System.Windows.Controls.Label lblColorRange8_2 = this.lblColorRange_8;
          string str111 = str1;
          num9 = scaleValueList[7];
          string str112 = num9.ToString();
          string str113 = str111 + str112;
          lblColorRange8_2.Content = (object) str113;
          System.Windows.Controls.Label lblColorRange7_3 = this.lblColorRange_7;
          string str114 = str1;
          num9 = scaleValueList[6];
          string str115 = num9.ToString();
          string str116 = str114 + str115;
          lblColorRange7_3.Content = (object) str116;
          System.Windows.Controls.Label lblColorRange6_4 = this.lblColorRange_6;
          string str117 = str1;
          num9 = scaleValueList[5];
          string str118 = num9.ToString();
          string str119 = str117 + str118;
          lblColorRange6_4.Content = (object) str119;
          System.Windows.Controls.Label lblColorRange5_5 = this.lblColorRange_5;
          string str120 = str1;
          num9 = scaleValueList[4];
          string str121 = num9.ToString();
          string str122 = str120 + str121;
          lblColorRange5_5.Content = (object) str122;
          System.Windows.Controls.Label lblColorRange4_6 = this.lblColorRange_4;
          string str123 = str1;
          num9 = scaleValueList[3];
          string str124 = num9.ToString();
          string str125 = str123 + str124;
          lblColorRange4_6.Content = (object) str125;
          System.Windows.Controls.Label lblColorRange3_7 = this.lblColorRange_3;
          string str126 = str1;
          num9 = scaleValueList[2];
          string str127 = num9.ToString();
          string str128 = str126 + str127;
          lblColorRange3_7.Content = (object) str128;
          System.Windows.Controls.Label lblColorRange2_8 = this.lblColorRange_2;
          string str129 = str1;
          num9 = scaleValueList[1];
          string str130 = num9.ToString();
          string str131 = str129 + str130;
          lblColorRange2_8.Content = (object) str131;
          System.Windows.Controls.Label lblColorRange1_8 = this.lblColorRange_1;
          string str132 = str1;
          num9 = scaleValueList[0];
          string str133 = num9.ToString();
          string str134 = str132 + str133;
          lblColorRange1_8.Content = (object) str134;
          break;
      }
      this.ShowScaleColorsAndValuesInDialog(num1 + 1);
    }
    else
    {
      this.lblColorRange_1.Content = (object) scaleValueList[0];
      this.lblColorRange_2.Content = (object) scaleValueList[1];
      this.lblColorRange_3.Content = (object) scaleValueList[2];
      this.lblColorRange_4.Content = (object) scaleValueList[3];
      this.lblColorRange_5.Content = (object) scaleValueList[4];
      this.lblColorRange_6.Content = (object) scaleValueList[5];
      this.lblColorRange_7.Content = (object) scaleValueList[6];
      this.lblColorRange_8.Content = (object) scaleValueList[7];
      this.lblColorRange_9.Content = (object) scaleValueList[8];
    }
  }

  private void ShowScaleColorsAndValuesInDialog(int numColors)
  {
    this.gScale_1.Height = 23.0;
    this.gScale_2.Height = 23.0;
    this.gScale_3.Height = numColors > 2 ? 23.0 : 0.0;
    this.gScale_4.Height = numColors > 3 ? 23.0 : 0.0;
    this.gScale_5.Height = numColors > 4 ? 23.0 : 0.0;
    this.gScale_6.Height = numColors > 5 ? 23.0 : 0.0;
    this.gScale_7.Height = numColors > 6 ? 23.0 : 0.0;
    this.gScale_8.Height = numColors > 7 ? 23.0 : 0.0;
    this.gScale_9.Height = numColors > 8 ? 23.0 : 0.0;
  }

  private void TxWindow_Closed(object sender, EventArgs e)
  {
    CApPaintDisplayCoverageManager.Instance.ReleaseViewModel();
    this.m_apVM.UnRegisterSimulationEvents();
    TxApplication.RefreshDisplay();
  }

  private void btnShowStaticCoverage_Click(object sender, RoutedEventArgs e)
  {
    CApPaintDisplayCoverageManager.Instance.CalculateStaticCoverage();
  }

  private void btnHSRFilter_Checked(object sender, RoutedEventArgs e)
  {
    CApPaintDisplayCoverageManager.Instance.HSRFilter = true;
  }

  private void btnHSRFilter_Unchecked(object sender, RoutedEventArgs e)
  {
    CApPaintDisplayCoverageManager.Instance.HSRFilter = false;
  }

  private void btnClose_Click(object sender, RoutedEventArgs e) => ((Window) this).Close();

  private void btnRemoveCoverage_Click(object sender, RoutedEventArgs e)
  {
    if (!CApPaintDeleteCoverageLogic.Instance.HandleBlankMeshesDeletion())
      return;
    this.m_apVM.IsMeshEmphasizing = true;
    ((DispatcherObject) this).Dispatcher.Invoke(DispatcherPriority.Background, (Delegate) (() => { }));
    CApPaintDeleteCoverageLogic.Instance.HandleDeleteCoverage();
    this.m_apVM.IsMeshEmphasizing = false;
    this.btnShowMeshes.IsChecked = new bool?(false);
  }

  private void btnReloadFiles_Click(object sender, RoutedEventArgs e)
  {
    string thicknessScaleName = this.m_apVM.SelectedThicknessScaleName;
    if (CUiPaintDisplayCoverageUtil.ReloadFiles(true))
    {
      this.m_apVM.UpdateScaleNameList();
      List<string> scaleNameList = this.m_apVM.ScaleNameList;
      this.m_apVM.SelectedThicknessScaleName = !this.m_apVM.ScaleNameList.Contains(thicknessScaleName) ? "ColorScale" : thicknessScaleName;
    }
    this.UpdateThicknessScaleInDialog();
    CUiPaintDisplayCoverageUtil.RedrawMeshesUsingCurrentScale();
  }

  private void Button_PreviewMouseDown(object sender, MouseButtonEventArgs e)
  {
    if (e.ClickCount < 2)
      return;
    e.Handled = true;
  }

  private void btnColorPicker_Click(object sender, RoutedEventArgs e)
  {
  }

  private void btnColorPicker_Closed(object sender, EventArgs e)
  {
    try
    {
      string html = ColorTranslator.ToHtml(this.m_colorPaletteWindow.SelectedColor);
      switch (this.m_editedColorIndex)
      {
        case 1:
          this.m_apVM.SelectedColor1 = html;
          break;
        case 2:
          this.m_apVM.SelectedColor2 = html;
          break;
        case 3:
          this.m_apVM.SelectedColor3 = html;
          break;
        case 4:
          this.m_apVM.SelectedColor4 = html;
          break;
        case 5:
          this.m_apVM.SelectedColor5 = html;
          break;
        case 6:
          this.m_apVM.SelectedColor6 = html;
          break;
        case 7:
          this.m_apVM.SelectedColor7 = html;
          break;
        case 8:
          this.m_apVM.SelectedColor8 = html;
          break;
        case 9:
          this.m_apVM.SelectedColor9 = html;
          break;
      }
    }
    catch (Exception ex)
    {
      string message = ex.Message;
    }
  }

  private void btnDisplayCoverageMode_Checked(object sender, RoutedEventArgs e)
  {
    CApPaintDisplayCoverageManager.Instance.DisplayCoverageMode = true;
    TxApplication.RefreshDisplay();
  }

  private void btnDisplayCoverageMode_Unchecked(object sender, RoutedEventArgs e)
  {
    CApPaintDisplayCoverageManager.Instance.DisplayCoverageMode = false;
    TxApplication.RefreshDisplay();
  }

  private void btnShowMeshes_Checked(object sender, RoutedEventArgs e)
  {
    this.m_apVM.IsMeshEmphasizing = true;
    ((DispatcherObject) this).Dispatcher.Invoke(DispatcherPriority.Background, (Delegate) (() => { }));
    Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
    Mouse.UpdateCursor();
    CApPaintDisplayCoverageManager.Instance.DisplayGrid();
    Mouse.OverrideCursor = (System.Windows.Input.Cursor) null;
    Mouse.UpdateCursor();
    TxApplication.RefreshDisplay();
    this.m_apVM.IsMeshEmphasizing = false;
  }

  private void btnShowMeshes_Unchecked(object sender, RoutedEventArgs e)
  {
    CApPaintDisplayCoverageManager.Instance.BlankGrid();
    TxApplication.RefreshDisplay();
  }

  private void btnDisplayedBrush_Checked(object sender, RoutedEventArgs e)
  {
    CApPaintDisplayCoverageManager.Instance.DisplayBrush = true;
  }

  private void btnDisplayedBrush_Unchecked(object sender, RoutedEventArgs e)
  {
    CApPaintDisplayCoverageManager.Instance.DisplayBrush = false;
  }

  private void btnDisplayThicknessValue_Checked(object sender, RoutedEventArgs e)
  {
    CApPaintDisplayCoverageManager.Instance.DisplayThicknessValue = true;
    TxApplication.RefreshDisplay();
  }

  private void btnDisplayThicknessValue_Unchecked(object sender, RoutedEventArgs e)
  {
    CApPaintDisplayCoverageManager.Instance.DisplayThicknessValue = false;
    TxApplication.RefreshDisplay();
  }

  private void cbScaleName_SelectionChanged(object sender, SelectionChangedEventArgs e)
  {
    if (this.cbScaleName.SelectedValue == null)
      return;
    CUiPaintDisplayCoverageUtil.SetThicknessScaleByName(this.cbScaleName.SelectedValue.ToString());
    this.UpdateThicknessScaleInDialog();
    CUiPaintDisplayCoverageUtil.RedrawMeshesUsingCurrentScale();
  }

  private void ShowColorsPalette(int i_color)
  {
    Color colorAtIndex = this.GetColorAtIndex(i_color);
    this.m_colorPaletteWindow = new TxColorPalette();
    ((Window) this.m_colorPaletteWindow).Closed += new EventHandler(this.btnColorPicker_Closed);
    this.m_colorPaletteWindow.SelectedColor = colorAtIndex;
    this.m_colorPaletteWindow.ShouldAutoPosition = false;
    this.PositionThePalette();
    ((Window) this.m_colorPaletteWindow).Show();
    this.RepositionThePaletteToBeWithinScreen();
  }

  private void PositionThePalette()
  {
    System.Windows.Point screen = this.gScale.PointToScreen(new System.Windows.Point(0.0, 0.0));
    ((Window) this.m_colorPaletteWindow).Left = screen.X + 23.0;
    ((Window) this.m_colorPaletteWindow).Top = screen.Y + 12.0 + (double) ((this.m_apVM.ScaleValueListSize + 1 - this.m_editedColorIndex) * 23);
  }

  private void RepositionThePaletteToBeWithinScreen()
  {
    this.gScale.PointToScreen(new System.Windows.Point(0.0, 0.0));
    int num = 0;
    foreach (Screen allScreen in Screen.AllScreens)
    {
      if (allScreen.Bounds.Right > num)
        num = allScreen.Bounds.Right;
    }
    if (((Window) this.m_colorPaletteWindow).Left + ((FrameworkElement) this.m_colorPaletteWindow).Width > (double) num)
    {
      TxColorPalette colorPaletteWindow = this.m_colorPaletteWindow;
      ((Window) colorPaletteWindow).Left = ((Window) colorPaletteWindow).Left - ((FrameworkElement) this.m_colorPaletteWindow).Width;
    }
    if (((Window) this.m_colorPaletteWindow).Top + ((FrameworkElement) this.m_colorPaletteWindow).Height <= (double) Screen.PrimaryScreen.Bounds.Bottom)
      return;
    TxColorPalette colorPaletteWindow1 = this.m_colorPaletteWindow;
    ((Window) colorPaletteWindow1).Top = ((Window) colorPaletteWindow1).Top - ((FrameworkElement) this.m_colorPaletteWindow).Height;
  }

  private Color GetColorAtIndex(int index)
  {
    Color selectedColor = this.m_colorPaletteWindow.SelectedColor;
    if (index > 0 && index <= this.m_apVM.ScaleValueListSize + 1)
      selectedColor = this.m_apVM.SelectedColorList[index - 1];
    return selectedColor;
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    System.Windows.Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/paint/displaycoverage/cuipaintdisplaycoveragewindow.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        ((Window) target).Closed += new EventHandler(this.TxWindow_Closed);
        break;
      case 2:
        this.btnHSRFilter = (System.Windows.Controls.CheckBox) target;
        this.btnHSRFilter.Checked += new RoutedEventHandler(this.btnHSRFilter_Checked);
        this.btnHSRFilter.Unchecked += new RoutedEventHandler(this.btnHSRFilter_Unchecked);
        break;
      case 3:
        this.btnShowMeshes = (System.Windows.Controls.CheckBox) target;
        this.btnShowMeshes.Checked += new RoutedEventHandler(this.btnShowMeshes_Checked);
        this.btnShowMeshes.Unchecked += new RoutedEventHandler(this.btnShowMeshes_Unchecked);
        break;
      case 4:
        this.btnDisplayedCoverageMode = (System.Windows.Controls.CheckBox) target;
        this.btnDisplayedCoverageMode.Checked += new RoutedEventHandler(this.btnDisplayCoverageMode_Checked);
        this.btnDisplayedCoverageMode.Unchecked += new RoutedEventHandler(this.btnDisplayCoverageMode_Unchecked);
        break;
      case 5:
        this.btnDisplayedBrush = (System.Windows.Controls.CheckBox) target;
        this.btnDisplayedBrush.Checked += new RoutedEventHandler(this.btnDisplayedBrush_Checked);
        this.btnDisplayedBrush.Unchecked += new RoutedEventHandler(this.btnDisplayedBrush_Unchecked);
        break;
      case 6:
        this.btnDisplayedThicknessValue = (System.Windows.Controls.CheckBox) target;
        this.btnDisplayedThicknessValue.Checked += new RoutedEventHandler(this.btnDisplayThicknessValue_Checked);
        this.btnDisplayedThicknessValue.Unchecked += new RoutedEventHandler(this.btnDisplayThicknessValue_Unchecked);
        break;
      case 7:
        this.gColorScaleName = (Grid) target;
        break;
      case 8:
        this.cbScaleName = (System.Windows.Controls.ComboBox) target;
        this.cbScaleName.SelectionChanged += new SelectionChangedEventHandler(this.cbScaleName_SelectionChanged);
        break;
      case 9:
        this.gScale = (Grid) target;
        break;
      case 10:
        this.gScale_9 = (StackPanel) target;
        break;
      case 11:
        this.btnColorPicker_9 = (TxColorPickButton) target;
        this.btnColorPicker_9.Click += new RoutedEventHandler(this.btnColorPicker_Click);
        break;
      case 12:
        this.lblColorRange_9 = (System.Windows.Controls.Label) target;
        break;
      case 13:
        this.gScale_8 = (StackPanel) target;
        break;
      case 14:
        this.btnColorPicker_8 = (TxColorPickButton) target;
        this.btnColorPicker_8.Click += new RoutedEventHandler(this.btnColorPicker_Click);
        break;
      case 15:
        this.lblColorRange_8 = (System.Windows.Controls.Label) target;
        break;
      case 16 /*0x10*/:
        this.gScale_7 = (StackPanel) target;
        break;
      case 17:
        this.btnColorPicker_7 = (TxColorPickButton) target;
        this.btnColorPicker_7.Click += new RoutedEventHandler(this.btnColorPicker_Click);
        break;
      case 18:
        this.lblColorRange_7 = (System.Windows.Controls.Label) target;
        break;
      case 19:
        this.gScale_6 = (StackPanel) target;
        break;
      case 20:
        this.btnColorPicker_6 = (TxColorPickButton) target;
        this.btnColorPicker_6.Click += new RoutedEventHandler(this.btnColorPicker_Click);
        break;
      case 21:
        this.lblColorRange_6 = (System.Windows.Controls.Label) target;
        break;
      case 22:
        this.gScale_5 = (StackPanel) target;
        break;
      case 23:
        this.btnColorPicker_5 = (TxColorPickButton) target;
        this.btnColorPicker_5.Click += new RoutedEventHandler(this.btnColorPicker_Click);
        break;
      case 24:
        this.lblColorRange_5 = (System.Windows.Controls.Label) target;
        break;
      case 25:
        this.gScale_4 = (StackPanel) target;
        break;
      case 26:
        this.btnColorPicker_4 = (TxColorPickButton) target;
        this.btnColorPicker_4.Click += new RoutedEventHandler(this.btnColorPicker_Click);
        break;
      case 27:
        this.lblColorRange_4 = (System.Windows.Controls.Label) target;
        break;
      case 28:
        this.gScale_3 = (StackPanel) target;
        break;
      case 29:
        this.btnColorPicker_3 = (TxColorPickButton) target;
        this.btnColorPicker_3.Click += new RoutedEventHandler(this.btnColorPicker_Click);
        break;
      case 30:
        this.lblColorRange_3 = (System.Windows.Controls.Label) target;
        break;
      case 31 /*0x1F*/:
        this.gScale_2 = (StackPanel) target;
        break;
      case 32 /*0x20*/:
        this.btnColorPicker_2 = (TxColorPickButton) target;
        this.btnColorPicker_2.Click += new RoutedEventHandler(this.btnColorPicker_Click);
        break;
      case 33:
        this.lblColorRange_2 = (System.Windows.Controls.Label) target;
        break;
      case 34:
        this.gScale_1 = (StackPanel) target;
        break;
      case 35:
        this.btnColorPicker_1 = (TxColorPickButton) target;
        this.btnColorPicker_1.Click += new RoutedEventHandler(this.btnColorPicker_Click);
        break;
      case 36:
        this.lblColorRange_1 = (System.Windows.Controls.Label) target;
        break;
      case 37:
        this.btnReloadFiles = (System.Windows.Controls.Button) target;
        this.btnReloadFiles.Click += new RoutedEventHandler(this.btnReloadFiles_Click);
        break;
      case 38:
        this.btnRemoveCoverage = (System.Windows.Controls.Button) target;
        this.btnRemoveCoverage.Click += new RoutedEventHandler(this.btnRemoveCoverage_Click);
        break;
      case 39:
        this.btnClose = (System.Windows.Controls.Button) target;
        this.btnClose.Click += new RoutedEventHandler(this.btnClose_Click);
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
